package us.gaaoc.framework.dao;

import org.hibernate.Query;
import java.util.*;


import us.gaaoc.framework.businessmodel.Filing;
import us.gaaoc.framework.model.CaseRecord;
import us.gaaoc.framework.model.DocumentType;
/**
 * Home object for domain model class Court.
 * 
 * @see us.gaaoc.framework.model.Court
 * @author Hibernate Tools
 */
public class DocumentTypeDAOHibernate extends GenericHibernateDAO<DocumentType, String, DocumentTypeDAO>
implements  DocumentTypeDAO{

	protected DocumentTypeDAOHibernate() {}

	public DocumentType findByTypeDescription(String desc) {
		Query q = this.getSession().createQuery("from DocumentType dt where dt.description = ?");
		q.setString(0, desc);
		return (DocumentType) q.uniqueResult(); 
	}
	
	/**
	 * Finds Document Type by Code
	 * @param code
	 * @return
	 */
	public DocumentType findDocumentTypeByCode(String code) {
		Query q = this.getSession().createQuery("from DocumentType dt where dt.code = ?");
		q.setString(0, code);
		return (DocumentType) q.uniqueResult();
	}
/*	
	/**
	 * Method to query list of document types by code and description
	 * 
	 * returns List of Select Items filled with Document Type ID's and 
	 * 	descriptions
	 *
	@SuppressWarnings("unchecked")
	public List<DocumentType> findDocumentTypesByAliasType() {
		// Create a Query and initialize it
		LOG.debug("Inside getting DocumentTypesByAlias");
		ArrayList<DocumentType> documentTypes = new ArrayList<DocumentType>();
		
		Query q = this.getSession().createQuery("from DocumentType dt order by description");
		LOG.debug("Executed Query . . .");
		// Put the results of the query into Document Type Structures
		List l = q.list();
		Iterator i = l.iterator();
		while (i.hasNext()){
			/*Object[] results = (Object[])i.next();
			String code = (String) results[0];
			String description = (String) results[1];
		
	    	DocumentType dt = new DocumentType(code, description);
	    	documentTypes.add(dt);*
			documentTypes.add((DocumentType)i.next());
			
			
		}
		return documentTypes;
	}
	
	public void updateXslContent(String code, byte[]xslContent){
		DocumentType dt = this.findById(code, true);
		dt.setStyleSheet(xslContent);
		this.makePersistent(dt);
	}  */

	/* (non-Javadoc)
	 * @see us.gaaoc.framework.dao.DocumentTypeDAO#getDocumentTypeList(int)
	 */
	@SuppressWarnings("unchecked")
	public List<DocumentType> getDocumentTypeList(int docCategoryCode) {
		Query q = this.getSession().createQuery("from DocumentType dt where dt.docCategoryCode = ?");
		q.setInteger(0, docCategoryCode);
		return  q.list();
	}
}